package com.financial.service.heemoney.utils;


import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @anthor wenguoqiang
 * @date: 2019/01/15 16:23
 * @company 蒙泰互联网公司
 * @des
 **/


public class ParamUtils {

    private ParamUtils(){}

    //获取请求参数
    public static Map<String,String> getParamMap(HttpServletRequest request){
        Map map = new HashMap();
        //得到枚举类型的参数名称，参数名称若有重复的只能得到第一个
        Enumeration enums = request.getParameterNames();
        while (enums.hasMoreElements())
        {
            Object tempName =  enums.nextElement();
            if( tempName == null || "".equals(tempName.toString()) ){
                continue;
            }
            String paramName = tempName.toString();
            String paramValue = request.getParameter(paramName);
            //形成键值对应的map
            map.put(paramName, paramValue);
        }
        return map;
    }


    /**
     * 请求参数缺失校验
     * @param request
     * @param params
     */
    public static Object requestParamLackCheck(HttpServletRequest request , List params){
        return null;
    }


    /**
     * 对够样老接口进行适配
     * @param request
     * @return
     */
    public static Map<String, Object> getMapPrarmsFromJson(HttpServletRequest request) {

        String jsonParam = request.getParameter("jsonParam");
        System.out.println("未解密参数="+jsonParam);

    	/*String validateToken = LoginAppUserHelper.getLoginUserToken(sessionId,token);
		if(StringUtils.isEmpty(validateToken)){
			returnMap.put("return_code", ReturnCodeEnum.TOKENERROR.getKey());
			returnMap.put("message", ReturnCodeEnum.TOKENERROR.getValue());
		}*/


        //jsonParam=AESUtis.decrypt(jsonParam,AESUtis.password);
        //des解密
        //jsonParam=DESUtil.decode(jsonParam);
        System.out.println("解密后参数="+jsonParam);
        if ((jsonParam != null) && (jsonParam.contains("*"))) {
            jsonParam = jsonParam.replace("*", "#");
        }
        return (Map<String, Object>) JSON.parse(jsonParam);
    }

}
